#include  <iostream>
using namespace std;
struct student{
    char no[17];
    int trySeat;
    int realSeat;
};

int main()
{
    int N;
    cin>>N;
    student * pA[1001] = {NULL};
    for(int i = 0; i < N; i++)
    {
        pA[i] = new student;
        cin >> pA[i]->no >> pA[i]->trySeat >> pA[i]->realSeat;
    }
    int M;
    cin >> M;
    int inputSeat;
    for(int i = 0; i < M; i++)
    {
        cin >> inputSeat;
        for(int j = 0; j<N;j++)
        {
            if(pA[j]->trySeat == inputSeat)
            {
                cout<< pA[j]->no << " " << pA[j]->realSeat << endl;
                break;
            }
        }
    }

}